import urllib.request as ur





# 输入网址得到代理IP
#通常有分隔符,如空格,要使用strip去掉
import ip_list

# proxy_address = ur.urlopen("http://piping.mogumiao.com/proxy/api/get_ip_bs?appKey=6f838edb44644cdb8fd965521f5c9d38&count=1&expiryDate=0&format=2&newLine=1").read().decode().strip()
# print(proxy_address)
# print(ip_list.get_ip())

# 创建ProxyHandler
# 'http':ip:port
proxy_handler = ur.ProxyHandler(
    {
    # 'http':proxy_address
    'http':'163.204.247.122:9999'
    }
)
# 单个ip在1s内访问10次以上就会被封
# 新建opener对象
opener = ur.build_opener(proxy_handler)
request = ur.Request(url='https://edu.csdn.net/')
# 相当于ur.urlopen,不过使用代理ip访问
response = opener.open(request).read()
print(response)
with open('test.html','wb') as f :
    f.write(response)
